<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="108px">
      <el-form-item label="日期" prop="checkDate">
        <el-date-picker clearable size="small" style="width: 200px" v-model="queryParams.checkDate" type="date"
          value-format="yyyy-MM-dd" :picker-options="pickerOptions" placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="班级" prop="classId">
        <el-select v-model="queryParams.classId" filterable placeholder="请选择班级">
          <el-option v-for="item in classList" :key="item.id" :label="item.label" :value="item.id" size="small">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="幼儿姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入姓名" size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="info" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="studentList">
      <!--    <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="序号" align="center" width="50">
        <template slot-scope="scope">
          {{ scope.$index + (queryParams.pageNum - 1) * queryParams.pageSize + 1 }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="班级" prop="className" />
      <el-table-column align="center" label="姓名" prop="name" />
      <el-table-column label="性别" align="center" prop="studentSex">
        <template slot-scope="scope">
          <!-- <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.studentSex==0?'1':'0'"/> -->
          {{ scope.row.studentSex == 0 ? '女' : scope.row.studentSex == 1 ? '男' : '未知' }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="年龄" prop="studentAge" />
      <el-table-column align="center" label="身高" prop="heightStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.heightStatus == '0'">正常</div>
          <div v-if="scope.row.heightStatus == '1'" class="red-color">偏低</div>
          <div v-if="scope.row.heightStatus == '2'" class="red-color">过高</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="体重/kg" prop="weightStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.weightStatus == '0'">正常</div>
          <div v-if="scope.row.weightStatus == '1'" class="red-color">偏瘦</div>
          <div v-if="scope.row.weightStatus == '2'" class="red-color">偏胖</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="体温/°C" prop="temperatureStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.temperatureStatus == '1'" class="red-color">异常</div>
          <div v-if="scope.row.temperatureStatus == '0'">正常</div>
          <div v-if="scope.row.temperatureStatus == '2'">未检查</div>
          <div v-if="scope.row.temperatureStatus == '3'">未检出</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="牙齿" prop="teethStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.teethStatus == '1'" class="red-color">异常</div>
          <div v-if="scope.row.teethStatus == '0'">正常</div>
          <div v-if="scope.row.teethStatus == '2'">未检查</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="眼睛" prop="eyeStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.eyeStatus == '1'" class="red-color">异常</div>
          <div v-if="scope.row.eyeStatus == '0'">正常</div>
          <div v-if="scope.row.eyeStatus == '2'">未检查</div>
        </template>
      </el-table-column>
      <!-- <el-table-column  align="center" label="咽喉"  prop="shijia"></el-table-column> -->
      <el-table-column align="center" label="手部" prop="handStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.handStatus == '1'" class="red-color">异常</div>
          <div v-if="scope.row.handStatus == '0'">正常</div>
          <div v-if="scope.row.handStatus == '2'">未检查</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="口腔" prop="oralStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.oralStatus == '1'" class="red-color">异常</div>
          <div v-if="scope.row.oralStatus == '0'">正常</div>
          <div v-if="scope.row.oralStatus == '2'">未检查</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="指甲" prop="nailsStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.nailsStatus == '1'" class="red-color">过长</div>
          <div v-if="scope.row.nailsStatus == '0'">正常</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="外伤" prop="traumaStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.traumaStatus == '1'" class="red-color">异常</div>
          <div v-if="scope.row.traumaStatus == '0'">正常</div>
          <div v-if="scope.row.traumaStatus == '2'">未检查</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
        </template>
      </el-table-column>

    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 添加或修改毕业管理对话框 -->
    <el-dialog :close-on-click-modal="false" title="修改" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="身高/cm" prop="height">
          <el-input v-model="form.height" placeholder="请输入身高/cm" />
        </el-form-item>
        <el-form-item label="体重/kg" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入体重/kg" />
        </el-form-item>
        <el-form-item label="体温/°C" prop="temperature">
          <el-input v-model="form.temperature" placeholder="请输入体温/°C" />
        </el-form-item>
        <el-form-item label="牙齿" prop="teethStatus">
          <el-select v-model="form.teethStatus" placeholder="请选择牙齿状况">
            <el-option v-for="item in isNormalList" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="眼睛" prop="eyeStatus">
          <el-select v-model="form.eyeStatus" placeholder="请选择眼睛状况">
            <el-option v-for="item in isExamineList" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手部" prop="handStatus">
          <el-select v-model="form.handStatus" placeholder="请选择手部状况">
            <el-option v-for="item in isExamineList" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="口腔" prop="oralStatus">
          <el-select v-model="form.oralStatus" placeholder="请选择口腔状况">
            <el-option v-for="item in isExamineList" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="指甲" prop="nailsStatus">
          <el-select v-model="form.nailsStatus" placeholder="请选择指甲状况">
            <el-option v-for="item in nailExamineList" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="外伤" prop="traumaStatus">
          <el-select v-model="form.traumaStatus" placeholder="请选择外伤状况">
            <el-option v-for="item in isExamineList" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="其他症状" prop="others">
          <el-input v-model="form.others" placeholder="请输入其他症状" />
        </el-form-item>
        <el-form-item label="处理方式" prop="processingMethod">
          <el-select v-model="form.processingMethod" placeholder="请选择处理方式">
            <el-option v-for="dict in dict.type.processing_method" :key="dict.value" :label="dict.label"
              :value="dict.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="说明" prop="statement">
          <el-input v-model="form.statement" placeholder="请输入说明" />
        </el-form-item>
        <el-form-item label="图片上传" prop="beforeModification">
          <div style="text-align:center;width: 160px;">
            <ImageUpload @input="getImageBefore" :isShowTip="false" :limit="1"/>
          </div>
          <!-- <div style="text-align:center;width: 160px;">
            <ImageUpload @input="getImageUnder" :isShowTip="false" :limit="1"/>
            <span>修改中</span>
          </div> -->
          <!-- <div style="text-align:center;width: 160px;">
            <ImageUpload @input="getImageAfter" :isShowTip="false" :limit="1"/>
            <span>修改后</span>
          </div> -->
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>


import { selectClazz } from "@/api/base/clazz";
import { abnormalStudents, exportAbnormal, updateCheckStatus } from "@/api/base/ill";

import { formatDateOnly } from "@/utils";

export default {
  name: "gzt",
  dicts: ['sys_user_sex', 'processing_method'],
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        kigId: this.$store.getters.schoolCode,
        checkDate: formatDateOnly(new Date()),
      },
      classList: [],
      studentList: [],
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      // 是否显示弹出层
      open: false,
      nailExamineList: [
        {
          value: '0',
          label: '正常'
        },
        {
          value: '1',
          label: '过长'
        }
      ],//指甲状况
      isExamineList: [
        {
          value: '0',
          label: '正常'
        },
        {
          value: '1',
          label: '异常'
        },
        {
          value: '2',
          label: '未检查'
        }
      ],//异常,正常,未检查
      isNormalList: [
        {
          value: '0',
          label: '正常'
        },
        {
          value: '1',
          label: '异常'
        }
      ],//异常,正常
      form: {},
      // 表单校验
      rules: {
        height: [
          { required: true, message: "身高不能为空", trigger: "blur" }
        ],
        weight: [
          { required: true, message: "体重不能为空", trigger: "blur" }
        ],
        temperature: [
          { required: true, message: "体温不能为空", trigger: "blur" }
        ],
        teethStatus: [
          { required: true, message: "牙齿状况不能为空", trigger: "blur" }
        ],
        eyeStatus: [
          { required: true, message: "眼睛状况不能为空", trigger: "blur" }
        ],
        handStatus: [
          { required: true, message: "手部状况不能为空", trigger: "blur" }
        ],
        oralStatus: [
          { required: true, message: "口腔状况不能为空", trigger: "blur" }
        ],
        nailsStatus: [
          { required: true, message: "指甲状况不能为空", trigger: "blur" }
        ],
        traumaStatus: [
          { required: true, message: "外伤状况不能为空", trigger: "blur" }
        ],
      },
    };
  },
  created() {
    //班级
    this.getQueryClazzList();
    this.getList()
  },
  methods: {
    // 修改
    handleUpdate(row) {
      this.open = true
      this.form = row
    },
    // 获取修改前的图片
    getImageBefore(val) {
      this.form.afterModification = val
    },
    // // 获取修改中的图片
    // getImageUnder(val) {
    //   this.form.underModification = val
    // },
    // // 获取修改中的图片
    // getImageAfter(val) {
    //   this.form.afterModification = val
    // },
    // 导出
    handleExport() {
      this.handleQuery();
      exportAbnormal(this.queryParams).then(response => {
        this.download(response.msg);
      })
    },
    /** 查询学生列表 */
    async getList() {
      try {
        this.loading = true;
        const data = await abnormalStudents(this.queryParams);

        this.studentList = data.rows;
        console.log(this.studentList)
        this.total = data.total;
        this.loading = false;
      } catch (e) {
        console.log(e)
      }

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateCheckStatus(this.form).then(response => {
            this.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    /** 查询班级列表 */
    async getQueryClazzList() {
      try {
        this.loading = true;
        const { rows } = await selectClazz();
        this.classList = rows.map(item => {
          return {
            id: item.id,
            label: item.title,
          }
        })
        this.loading = false;
      } catch (e) {
        console.log(e)
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
  }
};
</script>
<style lang="scss" scoped>
.red-color {
  color: red;
}
</style>
